package at.markushi.ui.action;

import ohos.utils.Parcel;
import ohos.utils.Sequenceable;

/**
 * A LineSegment describes which lines within an Action are linked together
 */
public class LineSegment implements Sequenceable {

	public int[] indexes;

	public LineSegment(int... indexes) {
		this.indexes = indexes;
	}

	public int getStartIdx() {
		return indexes[0];
	}


	//序列化对象的内部构造器，必须实现
	public static final Sequenceable.Producer
			CREATOR = new Sequenceable.Producer
			() {
		public LineSegment createFromParcel(Parcel in) {    //从包裹中获取数据构造对象
			// Initialize an instance first, then do customized unmarshlling.
			LineSegment instance = new LineSegment();
			instance.unmarshalling(in);
			return instance;
		}   //必须实现Producer
	};

	//上面是传统的实体类的构造函数和getter、setter
	//下面是序列化的核心
	//向包裹中写入数据，包裹可以理解为一块内存区
	@Override
	public boolean marshalling(Parcel parcel) {
		return 	parcel.writeIntArray(indexes);
	}

	//从包裹中读取数据
	@Override
	public boolean unmarshalling(Parcel parcel) {
		this.indexes = parcel.readIntArray();
		return false;
	}
}